package model.resource;

public class RenewableResource extends Resource
{
	private int quantity;
	
	private final int MAX_QUANTITY = 5000;
	
	public RenewableResource(String type, int initQuantity)
	{
		super(type);
		if (initQuantity > MAX_QUANTITY)
			quantity = MAX_QUANTITY;
		else
			quantity = initQuantity;
	}
	
	public int getQuantity()
	{
		return quantity;
	}

	public int harvest(int amount)
	{
		if (amount > quantity)
		{
			amount = quantity;
			quantity = 0;
		}
		else
			quantity -= amount;
		
		return amount;
	}

	public void addToQuantity(int amount)
	{
		if (amount < 0)
			throw new IllegalArgumentException("Error: cannot add negative " +
												"resource values.");
		quantity += amount;
		
		if (quantity > MAX_QUANTITY)
			quantity = MAX_QUANTITY;
	}
}
